package com.chenjim.architecture.screen.login

import android.os.SystemClock
import com.chenjim.architecture.base.BaseViewModel
import com.chenjim.architecture.base.IIntent
import com.chenjim.architecture.base.IState
import com.chenjim.architecture.screen.login.LoginScreenVM.UiIntent
import com.chenjim.architecture.screen.login.LoginScreenVM.UiState
import dagger.hilt.android.lifecycle.HiltViewModel
import javax.inject.Inject

@HiltViewModel
class LoginScreenVM @Inject constructor() : BaseViewModel<UiState, UiIntent>(UiState()) {

    override suspend fun handleIntent(intent: UiIntent) {
        when (intent) {
            UiIntent.InitIntent -> {
                updateUiState { it.copy(success = false) }
            }

            UiIntent.LoginIntent -> {
                SystemClock.sleep(2000)
                dateStore.setLoggedIn(true)
                updateUiState { it.copy(success = !it.success) }
            }
        }
    }

    data class UiState(val success: Boolean = false) : IState

    sealed class UiIntent : IIntent {
        data object InitIntent : UiIntent()
        data object LoginIntent : UiIntent()
    }

}



